/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mybatis.xml;

import java.util.List;
import org.mybatis.model.BatisColumnTypeClass;
import org.mybatis.model.CheckItem;

/**
 *
 * @author ProjetGWTPhp
 */
public class Mapper {

    private String root;
    private List<Atributo> rootAtributos;
    private String baseData;
    private String nodoInsert;
    private List<CheckItem> insertAtributos;
    private String insertValor;
    private String nodoUpdate;
    private List<CheckItem> updateAtributos;
    private String updateValor;
    private String nodoDelete;
    private List<CheckItem> deleteAtributos;
    private String deleteValor;
    private String nodoSelect;
    private List<CheckItem> selectAtributos;
    private String selectValor;
    private String nodoResultado;
    private List<Atributo> resultMap;
    private List<BatisColumnTypeClass> listColumnProperty;

    public Mapper() {
    }

    public String getRoot() {
        return root;
    }

    public void setRoot(String root) {
        this.root = root;
    }

    public void setBaseData(String baseData) {
        this.baseData = baseData;
    }

    public List<Atributo> getRootAtributos() {
        return rootAtributos;
    }

    public void setRootAtributos(List<Atributo> rootAtributos) {
        this.rootAtributos = rootAtributos;
    }

    public String getNodoInsert() {
        return nodoInsert;
    }

    public void setNodoInsert(String nodoInsert) {
        this.nodoInsert = nodoInsert;
    }

    public List<CheckItem> getInsertAtributos() {
        return insertAtributos;
    }

    public void setInsertAtributos(List<CheckItem> insertAtributos) {
        this.insertAtributos = insertAtributos;
    }

    public String getInsertValor() {
        String insert = "\n INSERT INTO  " + this.baseData + "." + this.root + "(\n ";

        for (int x = 0; this.listColumnProperty.size() > x; x++) {
            if (x + 1 == this.listColumnProperty.size()) {
                insert += this.listColumnProperty.get(x).getCOLUMN_NAME() + ") \n";
            } else {
                insert += this.listColumnProperty.get(x).getCOLUMN_NAME() + ",\n";
            }
        }
        insert += " VALUE \n ( \n";

        for (int x = 0; this.listColumnProperty.size() > x; x++) {
            if (x + 1 == this.listColumnProperty.size()) {
                insert += "#{" + this.listColumnProperty.get(x).getCOLUMN_NAME() + "} \n ) \n";
            } else {
                insert += "#{" + this.listColumnProperty.get(x).getCOLUMN_NAME() + "}, \n";
            }
        }


        insertValor = insert;
        return insertValor;
    }

    public void setInsertValor(String insertValor) {
        this.insertValor = insertValor;
    }

    public String getNodoUpdate() {
        return nodoUpdate;
    }

    public void setNodoUpdate(String nodoUpdate) {
        this.nodoUpdate = nodoUpdate;
    }

    public List<CheckItem> getUpdateAtributos() {
        return updateAtributos;
    }

    public void setUpdateAtributos(List<CheckItem> updateAtributos) {
        this.updateAtributos = updateAtributos;
    }

    public String getUpdateValor() {
        String update = "\n UPDATE SET  " + this.baseData + "." + this.root + " \n";

        for (int x = 0; this.listColumnProperty.size() > x; x++) {
            if (x + 1 == this.listColumnProperty.size()) {
                update += this.listColumnProperty.get(x).getCOLUMN_NAME() + "= #{" + this.listColumnProperty.get(x).getCOLUMN_ALIAS() + "}\n";
            } else {
                update += this.listColumnProperty.get(x).getCOLUMN_NAME() + "= #{" + this.listColumnProperty.get(x).getCOLUMN_ALIAS() + "},\n";
            }
        }
        for (int x = 0; this.listColumnProperty.size() > x; x++) {
            if (this.listColumnProperty.get(x).getPRIMARY_KEY()) {
                update += " WHERE " + this.root + "." + this.listColumnProperty.get(x).getCOLUMN_NAME() + "=#{" + this.listColumnProperty.get(x).getCOLUMN_ALIAS() + "}\n";
            }
        }

        updateValor = update;
        return updateValor;
    }

    public void setUpdateValor(String updateValor) {
        this.updateValor = updateValor;
    }

    public String getNodoDelete() {
        return nodoDelete;
    }

    public void setNodoDelete(String nodoDelete) {
        this.nodoDelete = nodoDelete;
    }

    public List<CheckItem> getDeleteAtributos() {
        return deleteAtributos;
    }

    public void setDeleteAtributos(List<CheckItem> deleteAtributos) {
        this.deleteAtributos = deleteAtributos;
    }

    public String getDeleteValor() {
        return deleteValor;
    }

    public void setDeleteValor(String deleteValor) {
        this.deleteValor = deleteValor;
    }

    public String getNodoSelect() {
        return nodoSelect;
    }

    public void setNodoSelect(String nodoSelect) {
        this.nodoSelect = nodoSelect;
    }

    public List<CheckItem> getSelectAtributos() {
        return selectAtributos;
    }

    public void setSelectAtributos(List<CheckItem> selectAtributos) {
        this.selectAtributos = selectAtributos;
    }

    public String getSelectValor() {
        String select = "\n SELECT \n";

        for (int x = 0; this.listColumnProperty.size() > x; x++) {
            if (x + 1 == this.listColumnProperty.size()) {
                select += this.listColumnProperty.get(x).getCOLUMN_NAME() + " \n";
            } else {
                select += this.listColumnProperty.get(x).getCOLUMN_NAME() + ", \n";
            }
        }

        for (int x = 0; this.listColumnProperty.size() > x; x++) {
            if (this.listColumnProperty.get(x).getPRIMARY_KEY()) {
                select += " FROM " + this.root + "." + this.listColumnProperty.get(x).getCOLUMN_NAME() + "=#{" + this.listColumnProperty.get(x).getCOLUMN_ALIAS() + "}\n";
            }
        }


        selectValor = select;
        return selectValor;
    }

    public String getNodoResultado() {
        return nodoResultado;
    }

    public void setNodoResultado(String nodoResultado) {
        this.nodoResultado = nodoResultado;
    }

    public List<Atributo> getResultMap() {
        return resultMap;
    }

    public void setResultMap(List<Atributo> resultMap) {
        this.resultMap = resultMap;
    }

    public List<BatisColumnTypeClass> getListColumnProperty() {
        return listColumnProperty;
    }

    public void setListColumnProperty(List<BatisColumnTypeClass> listColumnProperty) {
        this.listColumnProperty = listColumnProperty;
    }
}
